package pert;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;

public class Task {
	String name;
	int duration;
	int criticalCost;
	List<String> preceedingTasks;
	HashSet<Task> dependencies = new HashSet<Task>();
	private String[] dependenciesReferences;

	public Task() {
		this.preceedingTasks = new LinkedList<String>();
	}

	public Task(String name, int duration) {
		this.name = name;
		this.duration = duration;
		this.preceedingTasks = new LinkedList<String>();
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getDuration() {
		return duration;
	}

	public void setDuration(int duration) {
		this.duration = duration;
	}

	public int getCriticalCost() {
		return criticalCost;
	}

	public void setCriticalCost(int criticalCost) {
		this.criticalCost = criticalCost;
	}

	public List<String> getPreceedingTasks() {
		return preceedingTasks;
	}

	public void setPreceedingTasks(List<String> preceedingTasks) {
		this.preceedingTasks = preceedingTasks;
	}

	public HashSet<Task> getDependencies() {
		return dependencies;
	}

	public void setDependencies(HashSet<Task> dependencies) {
		this.dependencies = dependencies;
	}

	public boolean isDependent(Task t) {
		if (dependencies.contains(t)) {
			return true;
		}
		for (Task dep : dependencies) {
			if (dep.isDependent(t)) {
				return true;
			}
		}
		return false;
	}

	public String[] getDependenciesReference() {
		return dependenciesReferences;
	}

	public void setDependenciesReference(String[] dependenciesReference) {
		this.dependenciesReferences = dependenciesReference;
	}

	public String toString() {
		return name + "(" + criticalCost + ")";
	}

}